<?php
/**
 * Created by PhpStorm.
 * User: change
 * Date: 2017/2/7
 * Time: 16:35
 * 广告
 */

namespace Admin\Model;


use Base\Model\BaseModel;
use Think\Page;

class AerainfoModel extends BaseModel
{
    protected $_link = array(
        'Aerainfo' => array(
            'mapping_type'=>self::BELONGS_TO,
            'class_name'    => 'aerainfo',
            'foreign_key' => 'aerainfo_id',
            'parent_key' => 'parent_id',
        )
    );
    protected $_auto = array(
        array('status', '1'),
    );
    public function pageToView($size, $relation = false,  $parse = null, $order = '')
    {
        $count = $this->where( $parse)->count();
        $Page = new Page($count, $size);
        $Page->lastSuffix = false;  //最后一页是否显示总页数
        $Page->rollPage = 8;    //分页栏每页显示的页数
        $Page->setConfig('prev', '上一页');
        $Page->setConfig('next', '下一页');
        $Page->setConfig('first', '第一页');
        $Page->setConfig('last', '最后一页');
        $Page->setConfig('theme', '%HEADER% %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%');
        $show = $Page->show();
        $list = $this->where($parse)->relation($relation)->order($order)->limit($Page->firstRow . ',' . $Page->listRows)->select();
        return array(
            'list' => $list,
            'page' => $show,
        );
    }

}